package presentation;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.SwingWorker;

public class ProgressWorker extends SwingWorker<Double, Double> {

	ApfelMannPanel apfelMannPanel;

	public ProgressWorker(ApfelMannPanel panel) {

		this.apfelMannPanel = panel;

	}

	@Override
	protected Double doInBackground() throws Exception {

		apfelMannPanel.addPropertyChangeListener(new PropertyChangeListener() {

			@Override
			public void propertyChange(PropertyChangeEvent arg0) {
				if ("Fortschritt".equals(arg0.getPropertyName())) {

					setProgress((int)((Double) (arg0.getNewValue())*100));

				}

			}
		});

		apfelMannPanel.generateImage();

		return 100d;
	}

}
